import { useIntersectionObserver } from '@vueuse/core'

export const LazyPlugin = { 
    install: (app, options) => {
        // 在这里编写插件代码
        app.directive('img-lazy', {
            /* ... */
            mounted(el, binding) {
                const {stop} = useIntersectionObserver(
                    el,
                    ([{ isIntersecting }]) => {
                        // console.log(isIntersecting);
                        if (isIntersecting) {
                            // console.log(el,binding.value);
                            el.src = binding.value;
                            stop();
                        }
                    },
                )
            },
        })
    }
}